﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace Czj_VoteSys.Models.Database
{
    public partial class Czj_VoteSysContext : DbContext
    {
        public Czj_VoteSysContext()
        {
        }

        public Czj_VoteSysContext(DbContextOptions<Czj_VoteSysContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Category> Categories { get; set; }
        public virtual DbSet<Company> Companies { get; set; }
        public virtual DbSet<Ticket> Tickets { get; set; }
        public virtual DbSet<User> Users { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=Czj_VoteSys;Integrated Security=SSPI");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Chinese_PRC_CI_AS");

            modelBuilder.Entity<Category>(entity =>
            {
                entity.HasKey(e => e.Cateid);

                entity.ToTable("Category");

                entity.Property(e => e.Cateid)
                    .ValueGeneratedNever()
                    .HasColumnName("cateid");

                entity.Property(e => e.Catename)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("catename");
            });

            modelBuilder.Entity<Company>(entity =>
            {
                entity.HasKey(e => e.Cid);

                entity.ToTable("Company");

                entity.Property(e => e.Cid)
                    .ValueGeneratedNever()
                    .HasColumnName("cid");

                entity.Property(e => e.Cateid).HasColumnName("cateid");

                entity.Property(e => e.Cname)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("cname");

                entity.Property(e => e.Detail)
                    .IsRequired()
                    .HasColumnName("detail");

                entity.Property(e => e.Logo)
                    .IsRequired()
                    .HasColumnName("logo");

                entity.Property(e => e.Propic1)
                    .IsRequired()
                    .HasColumnName("propic1");

                entity.Property(e => e.Propic2).HasColumnName("propic2");

                entity.Property(e => e.Propic3).HasColumnName("propic3");

                entity.Property(e => e.Propic4).HasColumnName("propic4");

                entity.Property(e => e.Propic5).HasColumnName("propic5");

                entity.Property(e => e.Winstaut).HasColumnName("winstaut");

                entity.Property(e => e.Wintime)
                    .HasColumnType("date")
                    .HasColumnName("wintime");
            });

            modelBuilder.Entity<Ticket>(entity =>
            {
                entity.HasNoKey();

                entity.ToTable("ticket");

                entity.Property(e => e.Cid).HasColumnName("cid");

                entity.Property(e => e.Tid).HasColumnName("tid");

                entity.Property(e => e.Ttime)
                    .HasColumnType("datetime")
                    .HasColumnName("ttime");

                entity.Property(e => e.Uid).HasColumnName("uid");
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.HasKey(e => e.Uid);

                entity.ToTable("User");

                entity.Property(e => e.Uid)
                    .ValueGeneratedNever()
                    .HasColumnName("uid");

                entity.Property(e => e.Email)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("email");

                entity.Property(e => e.Password)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("password");

                entity.Property(e => e.Password2)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("password2");

                entity.Property(e => e.Salt)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("salt");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
